import {
	arrayToObject
} from '../../../../assets/js/util.js'
export default {
	data() {
		return {
			/*当前页显示数量*/
			pageSize: 10,
			/*每页显示的数量*/
			pageSizes: [10, 20, 50, 100],
			/*dataTotal表数量*/
			dataTotal: 0,
			/*分页器*/
			currentPage: 1,
			loading: false,
			// 默认参数 和 URL
			SRC: '',
			DP: {
				p: '',
				f: ''
			},
			title: '实时auany划拨订单流水',
			xlsxTitle:'',
			// 设置时间 一周， 一月，  昨天
			pickerOptions: {
				shortcuts: [{
					text: '最近一周',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近一个月',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近三个月',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
						picker.$emit('pick', [start, end]);
					}
				}]
			},
			// 存放获取到的服务器数
			serviceAreas: [],
			// 存放获取到的类型
			types: [{
				"label":'游戏内订单',
				"value": '1'
			},{
				"label":'直冲订单',
				"value": '2'
			}],
			// 提交的表单
			form: {
				dateOne: '',
				dateStart: '',
				dateEnd: '',
				serviceArea: '0',
				auanyserverid: '',
				type: '',
				fulluserId: '',
				roleId: '',
				orderid: '',
				productid: '',
				platformOrderid: ''
			},
			// 表单验证
			rules: {
				serviceArea: [{
					required: true,
					message: '请选择区服',
					trigger: 'change'
				}],
				type: [{
					required: true,
					message: '请选择类型',
					trigger: 'change'
				}],
				fulluserId: [{
					min: 3,
					max: 50,
					message: '长度在 3 到 50 个字符',
					trigger: 'blur'
				}],
				roleId: [{
					min: 3,
					max: 50,
					message: '长度在 3 到 50 个字符',
					trigger: 'blur'
				}],
				orderid: [{
					min: 3,
					max: 50,
					message: '长度在 3 到 50 个字符',
					trigger: 'blur'
				}],
				productid: [{
					min: 3,
					max: 50,
					message: '长度在 3 到 50 个字符',
					trigger: 'blur'
				}],
				platformOrderid: [{
					min: 3,
					max: 50,
					message: '长度在 3 到 50 个字符',
					trigger: 'blur'
				}],
				auanyserverid:  [{
					min: 3,
					max: 50,
					message: '长度在 3 到 50 个字符',
					trigger: 'blur'
				}]
			},
			// 工会ID输入框的宽
			inputWidth: '220px',
			// 所有el-form-item label的宽度
			formLabelWidth: '120px',
			/*表格数据*/
			tableData: [],
			/*表格数据全部*/
			tableDataAll: [],
			/*realTimeServiceContent 的宽*/
			realTimeServiceContent: '100%',
			/*表的宽度*/
			realTimeServiceTableWidth: "100%",
			/*数据表头*/
			tableHeader: [
				{prop:'innerId',label:'详细时间',width:'140px'},
				{prop:'plat',label:'服务器主机名',width:'160px'},
				{prop:'channel',label:'模块名',width:'100px'},
				{prop:'serviceArea',label:'游戏ID',width:'100px'},
				{prop:'accountId',label:'au服务器编号',width:'180px'},
				{prop:'roleId',label:'日志id',width:'100px'},
				{prop:'roleGrade1',label:'日志类型',width:'130px'},
				{prop:'roleGrade2',label:'订单类型',width:'130px'},
				{prop:'VIPGrade1',label:'全用户名',width:'130px'},
				{prop:'VIPGrade2',label:'区服id',width:'100px'},
				{prop:'VIPGrade3',label:'角色id',width:'100px'},
				{prop:'VIPGrade4',label:'游戏订单号',width:'140px'},
				{prop:'VIPGrade5',label:'订单创建时间',width:'180px'},
				{prop:'VIPGrade6',label:'订单游戏产品id',width:'180px'},
				{prop:'VIPGrade7',label:'订单货币类型',width:'180px'},
				{prop:'VIPGrade8',label:'订单总金额',width:'160px'},
				{prop:'VIPGrade9',label:'渠道名',width:'140px'},
				{prop:'VIPGrade10',label:'平台订单号',width:'140px'},
				{prop:'VIPGrade11',label:'平台产品id',width:'160px'},
				{prop:'VIPGrade12',label:'平台货币类型',width:'180px'},
				{prop:'VIPGrade13',label:'平台充值金额',width:'180px'},
				{prop:'VIPGrade14',label:'平台充值金额',width:'180px'},
				{prop:'VIPGrade15',label:'游戏货币数量',width:'180px'},
				{prop:'VIPGrade16',label:'额外游戏货币数量',width:'190px'},
				{prop:'VIPGrade17',label:'操作结果',width:'140px'},
				{prop:'VIPGrade18',label:'通讯序列号1',width:'160px'},
				{prop:'VIPGrade19',label:'通讯序列号2',width:'160px'},
				{prop:'VIPGrade20',label:'扩展字段1',width:'140px'},
				{prop:'VIPGrade21',label:'扩展字段2',width:'140px'}]
		}
	},
	computed: {
		// xlsx() {
		// 	return this.title + '.xlsx'
		// }
	},
	methods: {
		// 通用 成功 与 失败
		successFun(data) {
			this.$message({
				message: data,
				type: 'success'
			});
		},
		errorFun(data) {
			this.$message.error(data);
		},
		// 分页器
		// 控制每页的数量
		handleSizeChange(val) {
			this.pageSize = val;
			this.tableControl();
		},
		// 页数
		handleCurrentChange(val) {
			this.currentPage = val;
			this.tableControl();
		},
		tableControl() {
			this.tableData = this.tableDataAll.slice((this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize)
		},
		// 时间改变 得到起始时间和结束时间
		dateChange(val) {
			var t = val.split(' - ')
			this.form.dateStart = t[0];
			this.form.dateEnd = t[1];
		},
		// 提交数据
		commitData() {
			var that = this;
			var p = new Promise(function(resolve, reject) {
				var obj = {
					"dateStart": that.form.dateStart,
					"dateEnd": that.form.dateEnd,
					"serverid": that.form.serviceArea,
					"auanyserverid": that.form.auanyserverid,
					"ordertype": that.form.type,
					"fulluserid": that.form.fulluserId,
					"roleid": that.form.roleId,
					"orderid": that.form.orderid,
					"productid": that.form.productid,
					"platformOrderid": that.form.platformOrderid
				}
				that.dataTotal = 0;
				that.loading = true;
				that.tableData = [];
				that.tableDataAll = [];
				obj = encodeURI(JSON.stringify(obj));
				that.$http.jsonp(`${that.SRC}data/get.do?p=${that.DP.p}&f=${that.DP.f}&a=search`,{
					params:{'ps':'params='+obj},
				}).then(function(res) {
					resolve(res.body)
				})
			})
			p.then(function(value) {
				that.loading = false;
				var data = JSON.parse(JSON.parse(value));
				if (parseInt(data["res"]) === 0) {
					that.dataTotal = data.data.length;
					if (data.data.length === 0) {
						that.errorFun("该账号暂无数据！")
					} else {
						that.tableDataAll = arrayToObject(that.tableHeader, data.data);
						that.tableControl();
					}
				} else {
					that.errorFun(data["msg"])
				}
			})
		},
		// 搜索
		search(form) {
			this.$refs[form].validate((valid) => {
				if (valid) {
					this.commitData()
				} else {
					this.errorFun('请完善输入的值！');
					return false;
				}
			});
		},
		//重置
		reset(form) {
			this.$refs[form].resetFields();
			this.getData("initParam.do");
		},
		/*获取区服列表数据*/
		getData: function(url) {
			var that = this;
			// 将数据push到选择框中
			var pushData = function(pushArr, attr, data) {
				that[pushArr] = [];
				for (var i in data[attr]) {
					that[pushArr].push({
						label: i,
						value: data[attr][i]
					})
				}
			};
			var p = new Promise(function(resolve, reject) {
				that.$http.jsonp(`${that.SRC}data/get.do?p=${that.DP.p}&f=${that.DP.f}&a=initParam`,{
				params:{'ps': '' }
				}).then(function(res) {
					resolve(res.body)
				})
			});
			p.then(function(value) {
				var data = JSON.parse(JSON.parse(value));
				if (parseInt(data["res"]) === 0) {
					// 后台select的数据
					var lists = ["serverItmes","types"];
					// 页面select名字
					var nameLists = ["serviceAreas","types"];
					for (var i = 0; i < lists.length; i++) {
						if (data[lists[i]] !== undefined) {
							pushData(nameLists[i], lists[i], data);
						}
					}
				} else {
					that.getErrorMsg(Number(data.res))
				}
			})
		},
		/*设置初始值*/
		_init() {
			window.addEventListener('resize', function() {
				/*修改表格的宽度*/
				this.realTimeServiceTableWidth = document.body.clientWidth - 240 + "px";
				this.realTimeServiceContent = document.body.clientWidth - 220 + "px";
			}.bind(this))
		},
		// 表格下载
		excel(val) {
			this.xlsxTitle = val+"-"+this.form.dateStart+"到"+this.form.dateEnd;

			this.downloadExl(this.tableHeader,this.tableData,this.xlsxTitle,this.title);
		}
	},
	mounted() {
		this._init()
		// 初始化URL
		this.SRC = this.$store.getters.src;
		this.DP.p = localStorage.getItem('ZULONGBIPROJECTID');
		this.DP.f = localStorage.getItem('ZULONGBIPAGEID');
		this.form.dateOne = [new Date(new Date().getTime() - 86400000), new Date()];
		this.getData("initParam.do")
	}
}